﻿<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Expires" content="0" />
    <meta http-equiv="kiben" content="no-cache" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="shortcut icon" href=" /favicon.ico" />
    <title>校园支付 - 设置我的常用银行</title>
    <link href="css/main.css" rel="stylesheet" type="text/css" media="all" />
    <link href="css/dialog.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery.1.6.2_mini.js" type="text/javascript"></script>
    <script src="js/dialog.js" type="text/javascript"></script>
    <script src="js/common.js" type="text/javascript"></script>
    <script src="js/service.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            //获取当前登录用户信息
            //GetCurrentUserBaseInfo();
            //获取我的常用银行
            GetMyBanks3();
            //获取所有银行
            GetAllBanks();

            $('#sp_AddMyBank').click(function () {
                $('#div_BankBox').show();
                $(this).hide();
            });

            $('#btn_AddSubmit').click(function () {
                var hasLen = $('input:[type=checkbox][name=chk_MyBank]').length;
                if (hasLen < 4) {
                    var forAdd = $('input:[type=checkbox][name=chk_Bank]:checked');
                    if (forAdd.length == 0) {
                        Alert('请至少选择一家银行！');
                        return;
                    }
                    if (forAdd.length > (4 - hasLen)) {
                        Alert('对不起，你最多还可以选择' + (4 - hasLen) + '家银行！');
                        return;
                    }

                    forAdd.each(function () {
                        var id = $(this).attr('value');
                        var toAddIup = $(this).clone().attr({ 'checked': false, 'name': 'chk_MyBank', 'id': 'chk_MyBank_' + id });
                        var toAddLb = $(this).next().clone().attr({ 'for': 'chk_MyBank_' + id }); ;
                        toAddIup.appendTo($('#div_MyBankBox'));
                        toAddLb.appendTo($('#div_MyBankBox'));

                        $(this).attr('checked', false).hide();
                        $(this).next().hide();
                    });
                    
                    var forExist = $('input:[type=checkbox][name=chk_MyBank]');
                    var bankItems = new Array();
                    forExist.each(function () {
                        var id = $(this).attr('value');
                        bankItems.push(id);
                    });
                    funSetUserBank(bankItems.join(','));
                    
                    CheckForShowRemoveBtn();
                } else {
                    Alert('对不起，最多只能设置4家常用银行');
                }
            });

            $('#sp_RemoveMyBank').click(function () {
                var hasLen = $('input:[type=checkbox][name=chk_MyBank]').length;
                if (hasLen > 0) {
                    var forRemove = $('input:[type=checkbox][name=chk_MyBank]:checked');
                    if (forRemove.length == 0) {
                        Alert('请选择您要移除的常用银行！');
                        return;
                    }

                    forRemove.each(function () {
                        var id = $(this).attr('value');
                        var ctlId = 'chk_Bank_' + id;
                        if ($('#' + ctlId).length == 0) {
                            var toRemoveIup = $(this).clone().attr({ 'checked': false, 'name': 'chk_Bank', 'id': ctlId });
                            var toRemoveLb = $(this).next().clone().attr({ 'for': ctlId }); ;

                            var lbPos = $('#div_AllBankListBox > label.other');
                            lbPos.before(toRemoveIup).before(toRemoveLb);
                            //toRemoveLb.appendTo($('#div_AllBankListBox'));

                            $(this).next().remove();
                            $(this).remove();
                        } else {
                            $(this).next().remove();
                            $(this).remove();
                            $('#' + ctlId).show();
                            $('#' + ctlId).next().show();
                        }
                    });
                    
                    var forExist = $('input:[type=checkbox][name=chk_MyBank]');
                    var bankItems = new Array();
                    forExist.each(function () {
                        var id = $(this).attr('value');
                        bankItems.push(id);
                    });
                    funSetUserBank(bankItems.join(','));
                    
                    CheckForShowRemoveBtn();
                } else {
                    Alert('对不起，您还没有常用银行');
                }
            });
        });

        var CheckForShowRemoveBtn = function () {
            if ($('input:[type=checkbox][name=chk_MyBank]').length > 0) {
                $('#sp_RemoveMyBank').show();
            } else {
                $('#sp_RemoveMyBank').hide();
            }

            if ($('input:[type=checkbox][name=chk_MyBank]').length < 4 && $('#div_BankBox').css('display') == 'none' && $('#sp_AddMyBank').css('display') == 'none') {
                $('#sp_AddMyBank').show();
            }
        };   
    </script>
</head>
<body>
    <!--头部区域-->
    <div id="header">
        <!-- <a href="help.html" target="_blank" title="帮助"></a> -->
        <a href="quit.action" title="退出"></a>
    </div>
    <!--用户信息区域-->
    <div id="userBlock">
        <!--用户头像-->
        <div class="headIconBox">
            <img id="img_UserIcon" src="<s:property value="userIcon"/>" alt="用户头像" />
            <p title="点击更改头像"></p>
        </div>
        <!--用户个人账户信息-->
        <div class="baseInfoBox">
            <ul>
                <li id="li_UserName"><s:property value="hello"/></li>
                <li id="li_UserNo">学  号：<s:property value="userNo"/></li>
                <li class="last" id="li_LastLoginTime">最后一次登录时间：<s:property value="loginTime"/></li>
            </ul>
        </div> 
    </div>

    <div class="block">
        <p class="bankLogo"></p>
        <div class="blockTitle">常用银行</div>
        <div class="myBankInfo">
            <span>最多可以设置</span>
            <span class="money"> 4 </span>
            <span>家常用银行</span>
            <span class="add" id="sp_AddMyBank" title="添加常用银行"></span>
            <span class="sub" id="sp_RemoveMyBank" title="删除常用银行"></span>
        </div>
        <div class="myBankBox" id="div_MyBankBox"></div>
        <div class="myBankInfo"></div>
    </div>

    <div class="block" id="div_BankBox" style="display:none;">
        <div class="blockTitle">常用银行</div>
        <div class="myBankBox" id="div_AllBankListBox"></div>
        <div class="userBox">
            <ul>
                <li class="last">
                    <input type="button" name="btn_AddSubmit" id="btn_AddSubmit" value="添加" title="点击设置我的常用银行" />
                </li>
            </ul>
        </div>
    </div>

    <!--底部版权信息-->
    <!--<div id="footer">
        底部版权信息
    </div>-->
    <script type="text/javascript" src="js/footer.js"></script>
</body>
</html>